//
//  MCMainNavigationController.m
//  XTXOneToOne
//
//  Created by Canny on 2018/10/29.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "MCMainNavigationController.h"
#import "AppDelegate.h"

@interface MCMainNavigationController ()
typedef void(^MCMainNavigationControllerCompeletion)(BOOL result, NSDictionary *data );
@property (nonatomic,getter=isPushing)BOOL pushing;
@property (nonatomic,weak) UIView *coverView;

@property (nonatomic,assign) BOOL isOpen;

@end

@implementation MCMainNavigationController






+(void)load{
    
    UINavigationBar *bar =[UINavigationBar appearance];
    bar.barTintColor = MC_THEME_COLOR;
    bar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:16]};
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    //    viewController.navigationController.navigationBarHidden=NO;
    //    viewController.navigationController.navigationBar.translucent = NO;
   

    if (self.childViewControllers.count > 0) { // 如果push进来的不是第一个控制器
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"图层-6"] forState:UIControlStateHighlighted];
        [button setTitle:@"返回" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        button.size = CGSizeMake(90, 40);
        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        button.contentEdgeInsets = UIEdgeInsetsMake(0, -7, 0, 0);
        
        [button addTarget:self action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];

        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    
    [super pushViewController:viewController animated:animated];
}

- (void)popBackToViewController{
    

    [UIView animateWithDuration:0.01 animations:^{
        // nothing
    } completion:^(BOOL finished) {
        if (finished) {
            
            [self popToRootViewControllerAnimated:YES];
            [self popViewControllerAnimated:YES];
            return;
        }
    }];
}



@end















